Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blocks: various optimizations #39734

Open
wants to merge 21 commits into
base: trunk
Choose a base branch
from
Open

Conversation

kraftbj
Copy link
Contributor

@kraftbj kraftbj commented Oct 10, 2024

Proposed changes:

  • Adding various small optimizations in an attempt to make load_independent_blocks more performant.
  • Extension prefix: previously we would search the strings to add/remove jetpack/ from block names continually. Instead of doing those runs, standardize all blocks to only have their unprefixed version e.g. donations so we only need to add it when we need it and we don't need to waste cycles on figuring out if we need to add/remove it. This simplifies the block loading tooling. We still check for the prefix in the userland space.
  • Manifest is present. Previously, there used to be multiple manifest files possible, but we've stuck with only index.json for awhile. We can simplify the code by not needing the name value to be passed and assume it is already present.
  • Caching index.json - we can store this in memory after first read to avoid multiple file reads.
  • Block Discovery - we take the manifest and search in multiple directories for matching blocks. Two of these directories will never contain a block (at least as of now) and so let's not waste the cycles with them.
  • Minor function moves—with blocks as a module, we can move a couple of calls out of the main Jetpack class to the blocks module file.
  • Consolidation of function calls. The AI Assistant ran through a number of filter adds all on the same filter. We can simplify by just running one callable attached to the function instead of a dozen.
  • Hard code directories— there were some instances within each block of determining the block name based on the block folder, which seems like added complexity. If there's nothing dynamic about it, we can simply insert the name directly into the code.

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

Does this pull request change what data or activity we track or use?

Testing instructions:

  • Verify blocks still load.
  • You can add do_action( 'qm/start', 'jp_ind_blocks' ); // phpcs:ignore and do_action( 'qm/stop', 'jp_ind_blocks' ); // phpcs:ignore at the start and end of the Jetpack_Gutenberg::load_indepedent_blocks function to measure the difference.

For my testing, there is some difference, but not enough for me to say it is fully optimized. Need to rework a lot of this, I think, to make it more performant.

Copy link
Contributor

github-actions bot commented Oct 10, 2024

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WordPress.com Simple site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin, and enable the add/performance-improvements branch.

    • For jetpack-mu-wpcom changes, also add define( 'JETPACK_MU_WPCOM_LOAD_VIA_BETA_PLUGIN', true ); to your wp-config.php file.
  • To test on Simple, run the following command on your sandbox:

    bin/jetpack-downloader test jetpack add/performance-improvements
    
    bin/jetpack-downloader test jetpack-mu-wpcom-plugin add/performance-improvements
    

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

Copy link
Contributor

github-actions bot commented Oct 10, 2024

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • 🔴 Add a "[Status]" label (In Progress, Needs Team Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available.


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Choose a review path based on your changes:
    • A. Team Review: add the "[Status] Needs Team Review" label
      • For most changes, including minor cross-team impacts.
      • Example: Updating a team-specific component or a small change to a shared library.
    • B. Crew Review: add the "[Status] Needs Review" label
      • For significant changes to core functionality.
      • Example: Major updates to a shared library or complex features.
    • C. Both: Start with Team, then request Crew
      • For complex changes or when you need extra confidence.
      • Example: Refactor affecting multiple systems.
  3. Get at least one approval before merging.

Still unsure? Reach out in #jetpack-developers for guidance!


Jetpack plugin:

The Jetpack plugin has different release cadences depending on the platform:

  • WordPress.com Simple releases happen semi-continuously (PCYsg-Jjm-p2).
  • WoA releases happen weekly.
  • Releases to self-hosted sites happen monthly. The next release is scheduled for none scheduled (scheduled code freeze on undefined).

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.

@kraftbj kraftbj requested a review from jeherve October 15, 2024 16:32
@kraftbj
Copy link
Contributor Author

kraftbj commented Oct 15, 2024

The prefix_exists seem to be helpful during unit tests. Will need to work around that.

Copy link
Member

@jeherve jeherve left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking good and tests well. I only have some minor, non-blocking remarks, that could be addressed in a follow-up PR if you prefer.

Jetpack_Gutenberg::set_extension_available( 'ai-general-purpose-image-generator' );
Jetpack_Gutenberg::set_extension_available( 'ai-assistant-site-logo-support' );
Jetpack_Gutenberg::set_extension_available( 'ai-title-optimization-keywords-support' );
if ( apply_filters( 'breve_enabled', true ) ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe that's a good opportunity to add a docblock for this filter?

Comment on lines +64 to +74
Jetpack_Gutenberg::set_extension_available( 'ai-assistant-support' );
Jetpack_Gutenberg::set_extension_available( 'ai-assistant-form-support' );
Jetpack_Gutenberg::set_extension_available( 'ai-content-lens' );
Jetpack_Gutenberg::set_extension_available( 'ai-assistant-backend-prompts' );
Jetpack_Gutenberg::set_extension_available( 'ai-assistant-usage-panel' );
Jetpack_Gutenberg::set_extension_available( 'ai-featured-image-generator' );
Jetpack_Gutenberg::set_extension_available( 'ai-title-optimization' );
Jetpack_Gutenberg::set_extension_available( 'ai-assistant-experimental-image-generation-support' );
Jetpack_Gutenberg::set_extension_available( 'ai-general-purpose-image-generator' );
Jetpack_Gutenberg::set_extension_available( 'ai-assistant-site-logo-support' );
Jetpack_Gutenberg::set_extension_available( 'ai-title-optimization-keywords-support' );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think you could order them alphabetically? It would be easier to quickly parse, I think.

Comment on lines +64 to +74
Jetpack_Gutenberg::set_extension_available( 'ai-assistant-support' );
Jetpack_Gutenberg::set_extension_available( 'ai-assistant-form-support' );
Jetpack_Gutenberg::set_extension_available( 'ai-content-lens' );
Jetpack_Gutenberg::set_extension_available( 'ai-assistant-backend-prompts' );
Jetpack_Gutenberg::set_extension_available( 'ai-assistant-usage-panel' );
Jetpack_Gutenberg::set_extension_available( 'ai-featured-image-generator' );
Jetpack_Gutenberg::set_extension_available( 'ai-title-optimization' );
Jetpack_Gutenberg::set_extension_available( 'ai-assistant-experimental-image-generation-support' );
Jetpack_Gutenberg::set_extension_available( 'ai-general-purpose-image-generator' );
Jetpack_Gutenberg::set_extension_available( 'ai-assistant-site-logo-support' );
Jetpack_Gutenberg::set_extension_available( 'ai-title-optimization-keywords-support' );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We now have an extra one, ai-list-to-table-transform, with an extra filter:

/**
* Register the `ai-list-to-table-transform` extension.
*/
add_action(
'jetpack_register_gutenberg_extensions',
function () {
if ( apply_filters( 'jetpack_ai_enabled', true ) &&
apply_filters( 'list_to_table_transform_enabled', false )
) {
\Jetpack_Gutenberg::set_extension_available( 'ai-list-to-table-transform' );
}
}
);

Maybe you can add it to the same function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't looked, but I wonder if there's any chance of renaming the filter to be prefixed with jetpack_ while we're in there.

Comment on lines +32 to +33
Jetpack_Gutenberg::load_independent_blocks();
Jetpack_Gutenberg::load_block_editor_extensions();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those 2 methods were hooked into plugins_loaded in class.jetpack.php. If we can switch them to being loaded in modules/blocks.php (does this mean loading them on after_setup_theme on the frontend), can we do the same with register_block_metadata_collection below?

@jeherve jeherve added [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! and removed [Status] Needs Team Review labels Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Ad [Block] AI Assistant [Block] Payment Buttons [Extension] Publicize Block editor plugin [Feature] Memberships [Feature] VideoPress A feature to help you upload and insert videos on your site. [Focus] Performance [mu wpcom Feature] Newspack Blocks [Package] Blocks [Package] Jetpack mu wpcom WordPress.com Features [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! [Tests] Includes Tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants